package com.boluo.web.controller.audit;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.boluo.audit.dto.AudCarPackageDTO;
import com.boluo.audit.dto.AuditedCarPackageDTO;
import com.boluo.audit.vo.HistoryAuditVO;
import com.boluo.business.domain.BusServiceItem;
import com.boluo.business.service.IBusServiceItemService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.FileCopyUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.boluo.common.annotation.Log;
import com.boluo.common.core.controller.BaseController;
import com.boluo.common.core.domain.AjaxResult;
import com.boluo.common.enums.BusinessType;
import com.boluo.audit.domain.AudCarPackage;
import com.boluo.audit.service.IAudCarPackageService;
import com.boluo.common.utils.poi.ExcelUtil;
import com.boluo.common.core.page.TableDataInfo;

/**
 * 套餐审核Controller
 * 
 * @author boluo
 * @date 2023-04-17
 */
@RestController
@RequestMapping("/audit/carPackage")
public class AudCarPackageController extends BaseController
{
    @Autowired
    private IAudCarPackageService audCarPackageService;

    /**
     * 撤销套餐审核
     */
    @Log(title = "套餐审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/cancelCarPackage/{instanceId}")
    public AjaxResult cancelCarPackage(@PathVariable("instanceId") String instanceId)
    {
        audCarPackageService.cancelCarPackage(instanceId);
        return AjaxResult.success("操作成功");
    }


    /**
     * 查询审核历史列表
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:done')")
    @GetMapping("/queryAuditHistorys/{instanceId}")
    public AjaxResult queryAuditHistorys(@PathVariable("instanceId") String instanceId)
    {
        List<HistoryAuditVO> list = audCarPackageService.queryAuditHistorys(instanceId);
        return AjaxResult.success(list);
    }
    /**
     * 查询我的已办套餐审核列表
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:done')")
    @GetMapping("/listDoneCarPackage")
    public TableDataInfo listDoneCarPackage()
    {
        startPage();
        List<AudCarPackage> list = audCarPackageService.listDoneCarPackage();
        return getDataTable(list);
    }

    /**
     * 查询流程信息图(任务节点高亮)
     * 响应文件内容
     * 方法写 void 由我们开发者来自定义响应内容
     */
    @PreAuthorize("@ss.hasPermi('audit:bpmnInfo:queryProcess')")
    @GetMapping(value = "/queryProcess/{instanceId}")
    public void queryProcess(@PathVariable("instanceId") String instanceId,HttpServletResponse response) throws IOException {
        // 把文件内容或者图拿搭配封装一个 InputStream对象
        InputStream in = audCarPackageService.getInputStream(instanceId);

        // response 写出去
        FileCopyUtils.copy(in,response.getOutputStream());
    }

    /**
     * 查询待办套餐审核列表
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:todo')")
    @GetMapping("/listToDoCarPackage")
    public TableDataInfo listToDoCarPackage()
    {
        startPage();
        List<AudCarPackage> list = audCarPackageService.listToDoCarPackage();
        return getDataTable(list);
    }

    /**
     * 新增流程实例
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:startAuditServiceItem')")
    @Log(title = "套餐审核", businessType = BusinessType.INSERT)
    @PostMapping("/startAuditServiceItem")
    public AjaxResult startAuditServiceItem( @RequestBody AudCarPackageDTO audCarPackagedto)
    {
        return toAjax(audCarPackageService.startAuditServiceItem(audCarPackagedto));
    }
    /**
     * 查询套餐审核列表
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:list')")
    @GetMapping("/list")
    public TableDataInfo list(AudCarPackage audCarPackage)
    {
        startPage();
        List<AudCarPackage> list = audCarPackageService.selectAudCarPackageList(audCarPackage);
        return getDataTable(list);
    }


    /**
     * 导出套餐审核列表
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:export')")
    @Log(title = "套餐审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AudCarPackage audCarPackage)
    {
        List<AudCarPackage> list = audCarPackageService.selectAudCarPackageList(audCarPackage);
        ExcelUtil<AudCarPackage> util = new ExcelUtil<AudCarPackage>(AudCarPackage.class);
        util.exportExcel(response, list, "套餐审核数据");
    }

    /**
     * 获取套餐审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(audCarPackageService.selectAudCarPackageById(id));
    }

    /**
     * 新增套餐审核
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:add')")
    @Log(title = "套餐审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AudCarPackage audCarPackage)
    {
        return toAjax(audCarPackageService.insertAudCarPackage(audCarPackage));
    }

    /**
     * 修改套餐审核
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:edit')")
    @Log(title = "套餐审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AudCarPackage audCarPackage)
    {
        return toAjax(audCarPackageService.updateAudCarPackage(audCarPackage));
    }

    /**
     * 删除套餐审核
     */
    @PreAuthorize("@ss.hasPermi('audit:carPackage:remove')")
    @Log(title = "套餐审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(audCarPackageService.deleteAudCarPackageByIds(ids));
    }

    /**
     * 套餐审核
     */
    @Log(title = "套餐审核", businessType = BusinessType.UPDATE)
    @PutMapping("/auditAuditServiceItem")
    public AjaxResult auditAuditServiceItem(@RequestBody AuditedCarPackageDTO auditedCarPackageDTO)
    {
        audCarPackageService.auditAuditServiceItem(auditedCarPackageDTO);
        return AjaxResult.success("操作成功");
    }


    /**
     * 查询流程信息图(任务节点高亮) (不用 bus_car_package)
     * 响应文件内容
     * 方法写 void 由我们开发者来自定义响应内容
     */
    /*@PreAuthorize("@ss.hasPermi('audit:bpmnInfo:queryProcess')")
    @GetMapping(value = "/queryProcess/{serviceId}")
    public void queryProcess(@PathVariable("serviceId") String serviceId,HttpServletResponse response) throws IOException {
        // 把文件内容或者图拿搭配封装一个 InputStream对象
        InputStream in = audCarPackageService.getInputStream(serviceId);

        // response 写出去
        FileCopyUtils.copy(in,response.getOutputStream());
    }
*/
    /**
     * 查询待办套餐审核列表 (不用 bus_car_package)
     */
   /* @PreAuthorize("@ss.hasPermi('audit:carPackage:todo')")
    @GetMapping("/listToDoCarPackage")
    public TableDataInfo listToDoCarPackage()
    {
        startPage();
        List<BusServiceItem> list = audCarPackageService.listToDoCarPackage();
        return getDataTable(list);
    }*/
    /**
     * 查询套餐审核列表(不使用 audCarPackage 表)
     */
    /*@PreAuthorize("@ss.hasPermi('audit:carPackage:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusServiceItem busServiceItem)
    {
        startPage();
        List<BusServiceItem> list = audCarPackageService.selectAudCarPackageList(busServiceItem);
        return getDataTable(list);
    }*/

    /**
     * 套餐审核(不使用 audCarPackage 表)
     */
   /* @Log(title = "套餐审核", businessType = BusinessType.UPDATE)
    @PutMapping("/auditAuditServiceItem")
    public AjaxResult auditAuditServiceItem(@RequestBody AuditedCarPackageDTO auditedCarPackageDTO)
    {
        audCarPackageService.auditAuditServiceItem(auditedCarPackageDTO);
        return AjaxResult.success("操作成功");
    }*/

}
